package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.dto.TypeAndId;
import org.jsola.hr.vo.CompoundHeadVO;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * 增减员计划派单人员表
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SocPlanDispatchUserQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "日期")
    private String date;

    @ApiParam(value = "姓名和身份证号")
    private String nameOrIdCard;

    @ApiParam(value = "社保账号")
    private String socAccount;

    @ApiParam(value = "医保账号")
    private String meAccount;

    @ApiParam(value = "公积金账号")
    private String pfAccount;

    @ApiParam(value = "参保城市Code")
    private String city;

    @ApiParam(value = "参保城市")
    private String cityName;

    @ApiParam(value = "签约主体")
    private String contractSubject;

    @ApiParam(value = "月份Id")
    private List<String> monthIdList;

    @ApiParam(value = "月份Id")
    private List<String> taskMonthIdList;

    @ApiParam(value = "员工Id")
    private List<String> empIdList;

    @ApiParam(value = "开始时间")
    private String beginTime;

    @ApiParam(value = "结束时间")
    private String endTime;

    @ApiParam(value = "用工单位Id")
    private List<String> companyIdList;

    @ApiParam(value = "导出表头")
    private List<CompoundHeadVO> exportHead;

    @ApiParam(value = "类型")
    private Integer feedbackFlag;

    @ApiParam(value = "是否填充")
    private Boolean fill;

    private TypeAndId type;

    @ApiParam(value = "排序字段", allowMultiple = true, type = "Order", example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;


    /**
     * 添加排序
     *
     * @param propertyName 属性名
     * @param desc         是否降序
     * @return this
     */
    public SocPlanDispatchUserQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName, desc));
        return this;
    }

}

